package com.szpx.controller.BEQController;

import com.szpx.entity.BEQ.kaiban;
import com.szpx.service.kaibanService;
import com.szpx.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/kaiban")
public class kaibanController {

    @Autowired
    private kaibanService kaibanService;

    /**
     * 获取所有课程列表(分页)
     */
    @GetMapping("/list")
    public PageResult<kaiban> getAllCourses(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return kaibanService.getAllCourses(page, size);
    }

    /**
     * 搜索课程(分页)
     */
    @GetMapping("/search")
    public PageResult<kaiban> searchCourses(
            @RequestParam(required = false) String courseName,
            @RequestParam(required = false) String coach,
            @RequestParam(required = false) String location,
            @RequestParam(required = false) String status,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        kaiban course = new kaiban();
        course.setCourseName(courseName);
        course.setCoach(coach);
        course.setLocation(location);
        course.setStatus(status);
        return kaibanService.searchCourses(course, page, size);
    }

    /**
     * 获取单个课程详情
     */
    @GetMapping("/get/{id}")
    public kaiban getCourseById(@PathVariable Integer id) {
        return kaibanService.getCourseById(id);
    }

    /**
     * 添加新课程
     */
    @PostMapping("/add")
    public boolean addCourse(@RequestBody kaiban course) {
        return kaibanService.addCourse(course);
    }

    /**
     * 更新课程
     */
    @PostMapping("/update")
    public boolean updateCourse(@RequestBody kaiban course) {
        return kaibanService.updateCourse(course);
    }

    /**
     * 删除课程
     */
    @DeleteMapping("/delete/{id}")
    public boolean deleteCourse(@PathVariable Integer id) {
        return kaibanService.deleteCourse(id);
    }

    /**
     * 显示课程管理页面
     */
    @GetMapping("/page")
    public ModelAndView showDrivingCoursesPage() {
        return new ModelAndView("BEQ/driving_courses");
    }
}